<?php

namespace Unl\HomologacionBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class SecurityController extends Controller {
    /**
     * Muestra la pantalla de control de acceso al sistema
     *
     * @Route("/login", name="login")
     * @Template()
     */
    public function loginAction() {
        $peticion = $this->getRequest();
        $sesion = $peticion->getSession();
        // obtiene el error de inicio de sesión si lo hay
        if ($peticion->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $peticion->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $sesion->get(SecurityContext::AUTHENTICATION_ERROR);
        }
        return $this->render('UnlHomologacionBundle:Security:login.html.twig', 
                array(
                    'last_username' => $sesion->get(SecurityContext::LAST_USERNAME),
                    'error'=> $error,));
    }
    
/**
     * Muestra la pantalla de control de acceso al sistema
     *
     * @Route("/login_check", name="login_check")
     * @Template()
     */
    public function loginCheckAction() {
        
    }    
    
    public function getTokenAction()
    {
        return new Response($this->container->get('form.csrf_provider')
            ->generateCsrfToken('authenticate'));
    }

}
